<!DOCTYPE html>
<html class="x-admin-sm">
    {include file='public/header'}
    <script src="/admin/xadmin/lib/layui/upload.js" charset="utf-8"></script>

    <body>
        <div class="x-body">
            <form class="layui-form" lay-filter="formAjax">
          

                <div class="layui-form-item" style="display: flex;">
                    <label class="layui-form-label">
                        小程序
                    </label>
                    <div id="applet" style="width: 100%;flex: 1;"></div>
                </div>
                <div class="layui-form-item" style="display: flex;">
                    <label class="layui-form-label">
                        注意项
                    </label>
                    <div style="width: 100%;flex: 1;">
                        授权小程序同时会绑定页面，这个操作需要时间等待，请勿关闭页面耐心等待。<br>
                        <span style="color: red">请选择在使用的小程序，勿授权还未使用的小程序。</span>
                    </div>
                </div>

                <input type="hidden" name="applet_ids" id="applet_ids" value=""/>
                <input type="hidden" name="id" id="id" value=""/>
                <button id="submitData" class="layui-btn" lay-submit lay-filter="submitData" style="display: none;"/>
            </form>
        </div>
        <script>
            let params = {
             
                editUrl: '/admin/mediaAssets/authorize'
            }
            form_ajax(params)
            let id = GetQueryString('id')
            $('#id').val(id)
            let str = GetQueryString('data')
            let datas= str.split(',')
        
            let xmSelectAppletOption = {
                url: '/admin/applet/select?type=2',
                initValue: '', // 初始值
                el: '#applet',
                showCount: 4,
                pageSize: 5,
                onFn: function (data) {
                    if (data.arr.length !== 0) {

                        let arr = data.arr.map(item => {
                            return item.id
                        })
                        $('input[name="applet_ids"]').val(arr)
                        
                    } else {
                        $('input[name="applet_ids"]').val('')
                    }
                }

            }
            xmSelectAppletOption.initValue =  datas
            xmSelectA(xmSelectAppletOption)

         


            if (id) {
                // Ajax(params.detailUrl, {
                //     id
                // }, 'get').then(result => {
                //     let arr = result.data.recharge_white.map(item => { // console.log(item);
                //         return item.company_id
                //     })
                //     xmSelectAppletOption.initValue = arr
                //     $('input[name="recharge_white_ids"]').val(arr)
                //     $('input[name="recharge_name"]').attr('disabled', true);
                //     $('#recharge_name').css("background", "#CCCCCC");
                //     $('#recharge_day').css("background", "#CCCCCC");
                //     $('#recharge_amount').css("background", "#CCCCCC");
                //     $('#recharge_set').css("background", "#CCCCCC");
                //     $('input[name="recharge_name"]').css("cursor", "not-allowed")
                //     $('input[name="recharge_day"]').attr('disabled', true);
                //     $('input[name="recharge_amount"]').attr('disabled', true);
                //     $('input[name="recharge_set"]').attr('disabled', true);
                //     xmSelectA(xmSelectAppletOption)

                // });
               
                xmSelectA(xmSelectAppletOption)
            } else {
                xmSelectA(xmSelectAppletOption)
            }
           
        </script>
    </body>

</html>
